﻿Imports VN.INS.BL.BC
Imports System.Data
Imports System.IO
Imports Microsoft.Office.Interop

Partial Class Devida_ReporteEvolucion
    Inherits System.Web.UI.Page

#Region "Constantes"
    Dim tmpChartName1 As String = "Evol1.jpg"
    Dim tmpChartName2 As String = "Evol2.jpg"
    Dim tmpChartName3 As String = "Evol3.jpg"
    Dim tmpChartName4 As String = "Evol4.jpg"
#End Region

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If (Not (Page.IsPostBack)) Then
            'muestra datos iniciales            
            lblTitulo.Text = "Reporte de evolución del avance financiero"
            ListaPeriodoInicio()
            ListaPeriodoFin()
            ListaRegion("")
            ListaAmbito("", ddlRegion.SelectedValue.ToString)
            ListaEjecutor("", ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
        End If
    End Sub

    Public Sub ListaPeriodoInicio()
        'carga combo periodo inicio
        Dim objGeneral As New GeneralBC
        Dim objDt As DataTable
        Try
            objGeneral = New GeneralBC
            objDt = New DataTable
            objDt = objGeneral.ListaPeriodoReporte("0", "ASC", Session("Año"))
            ViewState("Filas") = objDt.Rows.Count

            ddlPeriodoInicio.DataSource = objDt
            ddlPeriodoInicio.DataTextField = "DESCRIPCION"
            ddlPeriodoInicio.DataValueField = "PERIODO"
            ddlPeriodoInicio.DataBind()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub ListaPeriodoFin()
        'carga combo periodo fin
        Dim objGeneral As New GeneralBC
        Dim objDt As DataTable
        Try
            objGeneral = New GeneralBC
            objDt = New DataTable
            objDt = objGeneral.ListaPeriodoReporte("0", "DESC", Session("Año"))

            'Dim per As String = ddlPeriodoInicio.SelectedValue.ToString

            'For i As Int16 = 0 To objDt.Rows.Count - 1
            '    If per > objDt.Rows(i).Item("PERIODO").ToString Then
            '        objDt.Rows(i).Delete()
            '    End If
            'Next

            ddlPeriodoFin.DataSource = objDt
            ddlPeriodoFin.DataTextField = "DESCRIPCION"
            ddlPeriodoFin.DataValueField = "PERIODO"
            ddlPeriodoFin.DataBind()
        Catch ex As Exception
            Throw ex
        End Try
    End Sub

    Public Sub ListaRegion(ByVal strPPER As String)
        'carga combo region
        Dim objGeneral As GeneralBC
        Dim objData As DataTable
        objGeneral = New GeneralBC
        objData = New DataTable
        objData = objGeneral.ListaRegion(strPPER)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("NOMBRE") = "--Todos--"
        drusuariorow("UBIGEO") = ""
        objData.Rows.Add(drusuariorow)
        ddlRegion.DataSource = objData
        ddlRegion.DataTextField = "NOMBRE"
        ddlRegion.DataValueField = "UBIGEO"
        ddlRegion.DataBind()
        ddlRegion.SelectedValue = ""
    End Sub

    Public Sub ListaAmbito(ByVal strPPER As String, ByVal strRegion As String)
        'carga combo ambito
        Dim objReporte As ReporteBC
        Dim objData As DataTable
        objReporte = New ReporteBC
        objData = New DataTable
        objData = objReporte.ListaAmbito(strPPER, strRegion)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("DESCRIPCION") = "--Todos--"
        drusuariorow("CODIGO") = ""
        objData.Rows.Add(drusuariorow)
        ddlAmbito.DataSource = objData
        ddlAmbito.DataTextField = "DESCRIPCION"
        ddlAmbito.DataValueField = "CODIGO"
        ddlAmbito.DataBind()
        ddlAmbito.SelectedValue = ""
    End Sub

    Public Sub ListaEjecutor(ByVal strPPER As String, ByVal strRegion As String, ByVal strAmbito As String)
        'carga combo ejecutor
        Dim objReporte As ReporteBC
        Dim objData As DataTable
        objReporte = New ReporteBC
        objData = New DataTable
        objData = objReporte.ListaEjecutor(strPPER, strRegion, strAmbito)
        Dim drusuariorow As DataRow = objData.NewRow()
        drusuariorow("DESCRIPCION") = "--Todos--"
        drusuariorow("EJECUTOR") = ""
        objData.Rows.Add(drusuariorow)
        ddlEjecutor.DataSource = objData
        ddlEjecutor.DataTextField = "DESCRIPCION"
        ddlEjecutor.DataValueField = "EJECUTOR"
        ddlEjecutor.DataBind()
        ddlEjecutor.SelectedValue = ""
    End Sub

    Protected Sub ddlRegion_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlRegion.SelectedIndexChanged
        'carga combos enlazados
        ListaAmbito("", ddlRegion.SelectedValue.ToString)
        ListaEjecutor("", ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
    End Sub

    Protected Sub ddlAmbito_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlAmbito.SelectedIndexChanged
        'carga combo enlazado
        ListaEjecutor("", ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString)
    End Sub

    Protected Sub btnGenerar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnGenerar.Click
        'crea el reporte segun el filtro 
        If ViewState("Filas") > 0 Then
            'If DateTime.Parse(ddlPeriodoInicio.SelectedValue) > DateTime.Parse(ddlPeriodoFin.SelectedValue) Then
            If Integer.Parse(ddlPeriodoInicio.SelectedValue) > Integer.Parse(ddlPeriodoFin.SelectedValue) Then
                alerta.Mostrar_Alerta("Aviso", "El Periodo Inicio debe ser menor que el Final")
            Else
                lblPerIni.Text = ddlPeriodoInicio.SelectedItem.Text
                lblPerFin.Text = ddlPeriodoFin.SelectedItem.Text
                lblRegion.Text = ddlRegion.SelectedItem.Text
                lblAmbito.Text = ddlAmbito.SelectedItem.Text
                lblEjecutor.Text = ddlEjecutor.SelectedItem.Text

                Dim objReporte As ReporteBC
                Dim objData, objData1, objData2, objData3 As DataTable
                objReporte = New ReporteBC

                'GIRADO
                objData = New DataTable  'Todos los POAS menos los DU_DS = 1 (Girado)
                objData1 = New DataTable 'Todos los POAS (Girado)

                'DEVENGADO
                objData2 = New DataTable 'Todos los POAS menos los DU_DS = 1 (Devengado)
                objData3 = New DataTable 'Todos los POAS (Devengado)


                objData = objReporte.ReporteEvolucion(ddlPeriodoInicio.SelectedValue.ToString, ddlPeriodoFin.SelectedValue.ToString, _
                                                      ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString, _
                                                      ddlEjecutor.SelectedValue.ToString, "0", Session("Año"))

                objData1 = objReporte.ReporteEvolucion(ddlPeriodoInicio.SelectedValue.ToString, ddlPeriodoFin.SelectedValue.ToString, _
                                                      ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString, _
                                                      ddlEjecutor.SelectedValue.ToString, "", Session("Año"))

                gvEvolucion.DataSource = objData
                gvEvolucion.DataBind()

                gvGirado.DataSource = objData1
                gvGirado.DataBind()

                objData2 = objReporte.ReporteEvolucionDevengado(ddlPeriodoInicio.SelectedValue.ToString, ddlPeriodoFin.SelectedValue.ToString, _
                                                      ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString, _
                                                      ddlEjecutor.SelectedValue.ToString, "0", Session("Año"))
                objData3 = objReporte.ReporteEvolucionDevengado(ddlPeriodoInicio.SelectedValue.ToString, ddlPeriodoFin.SelectedValue.ToString, _
                                                      ddlRegion.SelectedValue.ToString, ddlAmbito.SelectedValue.ToString, _
                                                      ddlEjecutor.SelectedValue.ToString, "", Session("Año"))
                gvDevengado.DataSource = objData2
                gvDevengado.DataBind()
                gvDevengado2.DataSource = objData3
                gvDevengado2.DataBind()

                'Carga de los gráficos
                Chart(objData, objData2, objData1, objData3)

                objData = Nothing
                objData1 = Nothing
            End If

            Me.DivReporte.Style("display") = "inline"
        Else
            alerta.Mostrar_Alerta("Aviso", "No existen datos")
        End If

    End Sub

    Protected Sub ddlPeriodoInicio_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPeriodoInicio.SelectedIndexChanged
        'carga combo enlazado
        ListaPeriodoFin()
    End Sub

    Protected Sub btnExportar_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles btnExportar.Click
        'exporta reporte a excel
        If Me.DivReporte.Style("display") = "none" Then
            alerta.Mostrar_Alerta("Alerta", "Debe generar el reporte antes de exportar")
        Else
            Exportar()
        End If
    End Sub

    Public Sub Chart(ByVal objDt As DataTable, ByVal objDt1 As DataTable, ByVal objDt2 As DataTable, ByVal objDt3 As DataTable)
        'Chart1
        Try
            'llenamos matrices desde bd que estan contenidos en objDt,objDt1,objDt2,objDt3
            Dim x() As String = New String(objDt.Rows.Count - 1) {}
            Dim y() As Double = New Double(objDt.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt.Rows.Count - 1
                x(i) = objDt.Rows(i).Item("DESCRIPCION")
                y(i) = objDt.Rows(i).Item("PIRDAIS")
            Next

            Dim x1() As String = New String(objDt.Rows.Count - 1) {}
            Dim y1() As Double = New Double(objDt.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt.Rows.Count - 1
                x1(i) = objDt.Rows(i).Item("DESCRIPCION")
                y1(i) = objDt.Rows(i).Item("PTCD")
            Next
            Dim x2() As String = New String(objDt.Rows.Count - 1) {}
            Dim y2() As Double = New Double(objDt.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt.Rows.Count - 1
                x2(i) = objDt.Rows(i).Item("DESCRIPCION")
                y2(i) = objDt.Rows(i).Item("PPCOD")
            Next
            Dim x3() As String = New String(objDt.Rows.Count - 1) {}
            Dim y3() As Double = New Double(objDt.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt.Rows.Count - 1
                x3(i) = objDt.Rows(i).Item("DESCRIPCION")
                y3(i) = objDt.Rows(i).Item("TOTAL")
            Next
            Chart1.Series("PIRDAIS").Points.DataBindXY(x, y) 'Carga los datos a las series
            Chart1.Series("PTCD").Points.DataBindXY(x1, y1)
            Chart1.Series("PPCOD").Points.DataBindXY(x2, y2)
            Chart1.Series("TOTAL").Points.DataBindXY(x3, y3)
            Chart1.ChartAreas("ChartArea1").AxisX.Minimum = 1   'damos intervalo y tamaño variable aaarea
            Chart1.ChartAreas("ChartArea1").AxisX.Maximum = objDt.Rows.Count
            Chart1.ChartAreas("ChartArea1").AxisX.Interval = 1
            Dim colorSet() As Drawing.Color = New Drawing.Color(3) {} 'cargamos paleta de colores
            colorSet(0) = Drawing.Color.FromArgb(146, 208, 80)
            colorSet(1) = Drawing.Color.FromArgb(128, 0, 64)
            colorSet(2) = Drawing.Color.FromArgb(0, 153, 255)
            colorSet(3) = Drawing.Color.FromArgb(13, 73, 125)

            Chart1.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart1.PaletteCustomColors = colorSet   'Damos los colores de paleta nueva
            Chart1.Titles(0).Text = "Evolución de Avance Financiero Semanal (Girado)" ' damos titulo
        Catch ex As Exception
            Throw ex
        End Try
        'Guardamos imagen de chart
        Dim imgPath1 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName1
        Chart1.SaveImage(imgPath1)

        'Chart2
        Try
            Dim x() As String = New String(objDt1.Rows.Count - 1) {}
            Dim y() As Double = New Double(objDt1.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt1.Rows.Count - 1
                x(i) = objDt1.Rows(i).Item("DESCRIPCION")
                y(i) = objDt1.Rows(i).Item("PIRDAIS")
            Next

            Dim x1() As String = New String(objDt1.Rows.Count - 1) {}
            Dim y1() As Double = New Double(objDt1.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt1.Rows.Count - 1
                x1(i) = objDt1.Rows(i).Item("DESCRIPCION")
                y1(i) = objDt1.Rows(i).Item("PTCD")
            Next
            Dim x2() As String = New String(objDt1.Rows.Count - 1) {}
            Dim y2() As Double = New Double(objDt1.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt1.Rows.Count - 1
                x2(i) = objDt1.Rows(i).Item("DESCRIPCION")
                y2(i) = objDt1.Rows(i).Item("PPCOD")
            Next
            Dim x3() As String = New String(objDt1.Rows.Count - 1) {}
            Dim y3() As Double = New Double(objDt1.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt1.Rows.Count - 1
                x3(i) = objDt1.Rows(i).Item("DESCRIPCION")
                y3(i) = objDt1.Rows(i).Item("TOTAL")
            Next
            Chart2.Series("PIRDAIS").Points.DataBindXY(x, y)
            Chart2.Series("PTCD").Points.DataBindXY(x1, y1)
            Chart2.Series("PPCOD").Points.DataBindXY(x2, y2)
            Chart2.Series("TOTAL").Points.DataBindXY(x3, y3)
            Chart2.ChartAreas("ChartArea1").AxisX.Minimum = 1
            Chart2.ChartAreas("ChartArea1").AxisX.Maximum = objDt1.Rows.Count
            Chart2.ChartAreas("ChartArea1").AxisX.Interval = 1
            Dim colorSet() As Drawing.Color = New Drawing.Color(3) {}
            colorSet(0) = Drawing.Color.FromArgb(146, 208, 80)
            colorSet(1) = Drawing.Color.FromArgb(128, 0, 64)
            colorSet(2) = Drawing.Color.FromArgb(0, 153, 255)
            colorSet(3) = Drawing.Color.FromArgb(13, 73, 125)

            Chart2.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart2.PaletteCustomColors = colorSet
            Chart2.Titles(0).Text = "Evolución de Avance Financiero Semanal (Devengado)"
        Catch ex As Exception
            Throw ex
        End Try
        Dim imgPath2 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName2
        Chart2.SaveImage(imgPath2)
        '-------------------------------
        'Chart3
        Try
            Dim x() As String = New String(objDt2.Rows.Count - 1) {}
            Dim y() As Double = New Double(objDt2.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt2.Rows.Count - 1
                x(i) = objDt2.Rows(i).Item("DESCRIPCION")
                y(i) = objDt2.Rows(i).Item("PIRDAIS")
            Next

            Dim x1() As String = New String(objDt2.Rows.Count - 1) {}
            Dim y1() As Double = New Double(objDt2.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt2.Rows.Count - 1
                x1(i) = objDt2.Rows(i).Item("DESCRIPCION")
                y1(i) = objDt2.Rows(i).Item("PTCD")
            Next
            Dim x2() As String = New String(objDt2.Rows.Count - 1) {}
            Dim y2() As Double = New Double(objDt2.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt2.Rows.Count - 1
                x2(i) = objDt2.Rows(i).Item("DESCRIPCION")
                y2(i) = objDt2.Rows(i).Item("PPCOD")
            Next
            Dim x3() As String = New String(objDt2.Rows.Count - 1) {}
            Dim y3() As Double = New Double(objDt2.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt2.Rows.Count - 1
                x3(i) = objDt2.Rows(i).Item("DESCRIPCION")
                y3(i) = objDt2.Rows(i).Item("TOTAL")
            Next
            Chart3.Series("PIRDAIS").Points.DataBindXY(x, y)
            Chart3.Series("PTCD").Points.DataBindXY(x1, y1)
            Chart3.Series("PPCOD").Points.DataBindXY(x2, y2)
            Chart3.Series("TOTAL").Points.DataBindXY(x3, y3)
            Chart3.ChartAreas("ChartArea1").AxisX.Minimum = 1
            Chart3.ChartAreas("ChartArea1").AxisX.Maximum = objDt2.Rows.Count
            Chart3.ChartAreas("ChartArea1").AxisX.Interval = 1
            Dim colorSet() As Drawing.Color = New Drawing.Color(3) {}
            colorSet(0) = Drawing.Color.FromArgb(146, 208, 80)
            colorSet(1) = Drawing.Color.FromArgb(128, 0, 64)
            colorSet(2) = Drawing.Color.FromArgb(0, 153, 255)
            colorSet(3) = Drawing.Color.FromArgb(13, 73, 125)

            Chart3.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart3.PaletteCustomColors = colorSet
            Chart3.Titles(0).Text = "Evolución de Avance Financiero Semanal (Girado)"
        Catch ex As Exception
            Throw ex
        End Try
        Dim imgPath3 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName3
        Chart3.SaveImage(imgPath3)

        'Chart4
        Try
            Dim x() As String = New String(objDt3.Rows.Count - 1) {}
            Dim y() As Double = New Double(objDt3.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt3.Rows.Count - 1
                x(i) = objDt3.Rows(i).Item("DESCRIPCION")
                y(i) = objDt3.Rows(i).Item("PIRDAIS")
            Next

            Dim x1() As String = New String(objDt3.Rows.Count - 1) {}
            Dim y1() As Double = New Double(objDt3.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt3.Rows.Count - 1
                x1(i) = objDt3.Rows(i).Item("DESCRIPCION")
                y1(i) = objDt3.Rows(i).Item("PTCD")
            Next
            Dim x2() As String = New String(objDt3.Rows.Count - 1) {}
            Dim y2() As Double = New Double(objDt3.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt3.Rows.Count - 1
                x2(i) = objDt3.Rows(i).Item("DESCRIPCION")
                y2(i) = objDt3.Rows(i).Item("PPCOD")
            Next
            Dim x3() As String = New String(objDt3.Rows.Count - 1) {}
            Dim y3() As Double = New Double(objDt3.Rows.Count - 1) {}
            For i As Int16 = 0 To objDt3.Rows.Count - 1
                x3(i) = objDt3.Rows(i).Item("DESCRIPCION")
                y3(i) = objDt3.Rows(i).Item("TOTAL")
            Next
            Chart4.Series("PIRDAIS").Points.DataBindXY(x, y)
            Chart4.Series("PTCD").Points.DataBindXY(x1, y1)
            Chart4.Series("PPCOD").Points.DataBindXY(x2, y2)
            Chart4.Series("TOTAL").Points.DataBindXY(x3, y3)
            Chart4.ChartAreas("ChartArea1").AxisX.Minimum = 1
            Chart4.ChartAreas("ChartArea1").AxisX.Maximum = objDt3.Rows.Count
            Chart4.ChartAreas("ChartArea1").AxisX.Interval = 1
            Dim colorSet() As Drawing.Color = New Drawing.Color(3) {}
            colorSet(0) = Drawing.Color.FromArgb(146, 208, 80)
            colorSet(1) = Drawing.Color.FromArgb(128, 0, 64)
            colorSet(2) = Drawing.Color.FromArgb(0, 153, 255)
            colorSet(3) = Drawing.Color.FromArgb(13, 73, 125)

            Chart4.Palette = DataVisualization.Charting.ChartColorPalette.None
            Chart4.PaletteCustomColors = colorSet
            Chart4.Titles(0).Text = "Evolución de Avance Financiero Semanal (Devengado)"
        Catch ex As Exception
            Throw ex
        End Try
        Dim imgPath4 As String = HttpContext.Current.Request.PhysicalApplicationPath + tmpChartName4
        Chart4.SaveImage(imgPath4)
    End Sub

    Public Sub Exportar()
        Dim sb As StringBuilder = New StringBuilder()
        Dim sw As StringWriter = New StringWriter(sb)
        Dim htw As HtmlTextWriter = New HtmlTextWriter(sw)
        Dim pagina As Page = New Page
        'CREAR TITULO y datos de filtro
        Dim gvtitle1 As New Table
        Dim titulo1 As New TableCell()
        titulo1.RowSpan = 1
        titulo1.ColumnSpan = 13
        titulo1.Text = "Reporte de evolución del avance financiero"
        titulo1.Font.Name = "Calibri"
        titulo1.Font.Size = 13
        titulo1.Font.Bold = True
        titulo1.BackColor = Drawing.Color.White
        titulo1.HorizontalAlign = HorizontalAlign.Center
        titulo1.VerticalAlign = VerticalAlign.Middle
        Dim gvtitle2 As New Table
        Dim titulo2 As New TableCell()
        titulo2.RowSpan = 1
        titulo2.ColumnSpan = 10
        titulo2.Text = " "
        titulo2.Font.Name = "Calibri"
        titulo2.Font.Size = 11
        titulo2.Font.Bold = True
        titulo2.BackColor = Drawing.Color.White
        titulo2.HorizontalAlign = HorizontalAlign.Center
        titulo2.VerticalAlign = VerticalAlign.Middle
        Dim tb1 As New Table
        Dim tit1, tit12, tit13, tit14, celdaVacia0 As New TableCell()
        tit1.Text = "Periodo Inicio: "
        tit1.Font.Name = "Calibri"
        tit1.Font.Size = 11
        tit1.Font.Bold = True
        tit1.BackColor = Drawing.Color.White
        tit1.HorizontalAlign = HorizontalAlign.Left
        tit1.VerticalAlign = VerticalAlign.Middle
        tit12.Text = lblPerIni.Text
        tit13.Text = "Periodo Fin: "
        tit13.Font.Name = "Calibri"
        tit13.Font.Size = 11
        tit13.Font.Bold = True
        tit13.BackColor = Drawing.Color.White
        tit13.HorizontalAlign = HorizontalAlign.Left
        tit13.VerticalAlign = VerticalAlign.Middle
        tit14.Text = lblPerFin.Text
        celdaVacia0.Text = " "
        Dim tb2 As New Table
        Dim tit2, tit22 As New TableCell()
        tit2.RowSpan = 1
        tit2.Text = "Región: "
        tit2.Font.Name = "Calibri"
        tit2.Font.Size = 11
        tit2.Font.Bold = True
        tit2.BackColor = Drawing.Color.White
        tit2.HorizontalAlign = HorizontalAlign.Left
        tit22.Text = lblRegion.Text
        Dim tb3 As New Table
        Dim tit3, tit32 As New TableCell()
        tit3.RowSpan = 1
        tit3.Text = "Ambito: "
        tit3.Font.Name = "Calibri"
        tit3.Font.Size = 11
        tit3.Font.Bold = True
        tit3.BackColor = Drawing.Color.White
        tit3.HorizontalAlign = HorizontalAlign.Left
        tit3.VerticalAlign = VerticalAlign.Middle
        tit32.Text = lblAmbito.Text
        Dim headertitulo1 As New TableRow()
        headertitulo1.Cells.Add(titulo1)
        Dim headertitulo2 As New TableRow()
        headertitulo2.Cells.Add(titulo2)
        Dim h1 As New TableRow()
        h1.Cells.Add(tit1)
        h1.Cells.Add(tit12)
        h1.Cells.Add(celdaVacia0)
        h1.Cells.Add(tit13)
        h1.Cells.Add(tit14)
        Dim h2 As New TableRow()
        h2.Cells.Add(tit2)
        h2.Cells.Add(tit22)
        Dim h3 As New TableRow()
        h3.Cells.Add(tit3)
        h3.Cells.Add(tit32)
        Dim h4 As New TableRow()
        Dim tit4, tit42 As New TableCell()
        tit4.RowSpan = 1
        tit4.Text = "Ejecutor: "
        tit4.Font.Name = "Calibri"
        tit4.Font.Size = 11
        tit4.Font.Bold = True
        tit4.BackColor = Drawing.Color.White
        tit4.HorizontalAlign = HorizontalAlign.Left
        tit4.VerticalAlign = VerticalAlign.Middle
        tit42.Text = lblEjecutor.Text
        h4.Cells.Add(tit4)
        h4.Cells.Add(tit42)
        'Cargamos imagenes gurdadas
        Dim imgPath1 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName1)
        Dim imgPath2 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName2)
        Dim imgPath3 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName3)
        Dim imgPath4 As String = Request.Url.GetLeftPart(UriPartial.Authority) + VirtualPathUtility.ToAbsolute("~/" + tmpChartName4)
        'Llenamos imagenes en tablas html
        Dim ChartTable1 As String = "<Table ><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td colspan='4' align='center' style='background-color:#8DB4E2;font-weight: bold;border: 1px solid #666666'>Girado Anual</td><td></td><td><img src='" + imgPath1 + "' \></td></tr>" + _
                                    "</Table>"
        Dim ChartTable2 As String = "<Table ><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                   "<tr><td></td><td colspan='4' align='center' style='background-color:#8DB4E2;font-weight: bold;border: 1px solid #666666'>Devengado Anual</td><td></td><td><img src='" + imgPath2 + "' \></td></tr>" + _
                                   "</Table>"
        Dim ChartTable3 As String = "<Table ><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td colspan='4' align='center' style='background-color:#8DB4E2;font-weight: bold;border: 1px solid #666666'>Devengado Anual</td><td></td><td><img src='" + imgPath4 + "' \></td></tr>" + _
                                    "</Table>"
        Dim ChartTable4 As String = "<Table ><tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td></td><td></td><td></td><td></td><td></td><td></td></tr>" + _
                                    "<tr><td></td><td colspan='4' align='center' style='background-color:#8DB4E2;font-weight: bold;border: 1px solid #666666'>Girado Anual</td><td></td><td><img src='" + imgPath3 + "' \></td></tr>" + _
                                    "</Table>"
        'cargamos tablas con datos
        gvtitle1.Rows.Add(headertitulo1)
        gvtitle2.Rows.Add(headertitulo2)
        tb1.Rows.Add(h1)
        tb2.Rows.Add(h2)
        tb3.Rows.Add(h3)
        tb3.Rows.Add(h4)

        'Llenamos valores a la pagina 1
        Dim form = New HtmlForm
        pagina.EnableEventValidation = False
        pagina.DesignerInitialize()
        pagina.Controls.Add(form)
        form.Controls.Add(gvtitle1)
        form.Controls.Add(gvtitle2)
        form.Controls.Add(tb1)
        form.Controls.Add(tb2)
        form.Controls.Add(tb3)
        pagina.RenderControl(htw)

        'creamos y llenamos 4 paginas mas con respectivos valores
        Dim sb0 As StringBuilder = New StringBuilder()
        Dim sw0 As StringWriter = New StringWriter(sb0)
        Dim htw0 As HtmlTextWriter = New HtmlTextWriter(sw0)
        Dim pagina0 As Page = New Page
        Dim form0 = New HtmlForm
        pagina0.EnableEventValidation = False
        pagina0.DesignerInitialize()
        pagina0.Controls.Add(form0)
        form0.InnerHtml = ChartTable2
        form0.Controls.Add(gvDevengado)
        pagina0.RenderControl(htw0)

        Dim sb1 As StringBuilder = New StringBuilder()
        Dim sw1 As StringWriter = New StringWriter(sb1)
        Dim htw1 As HtmlTextWriter = New HtmlTextWriter(sw1)
        Dim pagina1 As Page = New Page
        Dim form1 = New HtmlForm
        pagina1.EnableEventValidation = False
        pagina1.DesignerInitialize()
        pagina1.Controls.Add(form1)
        form1.InnerHtml = ChartTable1
        form1.Controls.Add(gvEvolucion)
        pagina1.RenderControl(htw1)

        Dim sb2 As StringBuilder = New StringBuilder()
        Dim sw2 As StringWriter = New StringWriter(sb2)
        Dim htw2 As HtmlTextWriter = New HtmlTextWriter(sw2)
        Dim pagina2 As Page = New Page
        Dim form2 = New HtmlForm
        pagina2.EnableEventValidation = False
        pagina2.Controls.Add(form2)
        form2.InnerHtml = ChartTable3
        form2.Controls.Add(gvDevengado2)
        pagina2.RenderControl(htw2)

        Dim sb3 As StringBuilder = New StringBuilder()
        Dim sw3 As StringWriter = New StringWriter(sb3)
        Dim htw3 As HtmlTextWriter = New HtmlTextWriter(sw3)
        Dim pagina3 As Page = New Page
        Dim form3 = New HtmlForm
        pagina3.EnableEventValidation = False
        pagina3.Controls.Add(form3)
        form3.InnerHtml = ChartTable4
        form3.Controls.Add(gvGirado)
        pagina3.RenderControl(htw3)

        'Creamos el archivo excel con datos de las 5 paginas html
        Response.Clear()
        Response.Buffer = True
        Response.ContentType = "application/vnd.ms-excel"
        Response.AddHeader("Content-Disposition", "attachment;filename=ReporteEvolucion_" + Now.Date.Year.ToString + Now.Date.Month.ToString + Now.Date.Day.ToString + Now.Hour.ToString + Now.Minute.ToString + Now.Second.ToString + ".xls")
        Response.Charset = "UTF-8"
        Response.ContentEncoding = Encoding.Default
        Response.Write(sb.ToString())
        Response.Write(sb0.ToString())
        Response.Write(sb1.ToString())
        Response.Write(sb2.ToString())
        Response.Write(sb3.ToString())
        Response.End()
    End Sub

    Protected Sub gvDevengado_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDevengado.RowDataBound
        'damos formato a grilla devengado
        If e.Row.Cells(0).Text = "Periodo" Then
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.Cells(0).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(0).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(146, 208, 80)
            e.Row.Cells(1).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(1).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(204, 192, 218)
            e.Row.Cells(2).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(2).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(183, 222, 232)
            e.Row.Cells(3).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(3).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(13, 73, 125)
            e.Row.Cells(4).ForeColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
        Else
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(255, 255, 255)
        End If
    End Sub

    Protected Sub gvEvolucion_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvEvolucion.RowDataBound
        'damos formato a grilla girado
        If e.Row.Cells(0).Text = "Periodo" Then
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.Cells(0).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(0).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(146, 208, 80)
            e.Row.Cells(1).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(1).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(204, 192, 218)
            e.Row.Cells(2).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(2).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(183, 222, 232)
            e.Row.Cells(3).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(3).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(13, 73, 125)
            e.Row.Cells(4).ForeColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
        Else
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(255, 255, 255)
        End If
    End Sub

    Protected Sub gvDevengado2_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvDevengado2.RowDataBound
        'damos formato a grilla devengado 2
        If e.Row.Cells(0).Text = "Periodo" Then
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.Cells(0).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(0).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(146, 208, 80)
            e.Row.Cells(1).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(1).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(204, 192, 218)
            e.Row.Cells(2).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(2).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(183, 222, 232)
            e.Row.Cells(3).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(3).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(13, 73, 125)
            e.Row.Cells(4).ForeColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
        Else
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(255, 255, 255)
        End If
    End Sub

    Protected Sub gvGirado_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvGirado.RowDataBound
        'damos formato a grilla  girado 2
        If e.Row.Cells(0).Text = "Periodo" Then
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(141, 180, 226)
            e.Row.Cells(0).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(0).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(146, 208, 80)
            e.Row.Cells(1).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(1).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(204, 192, 218)
            e.Row.Cells(2).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(2).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(183, 222, 232)
            e.Row.Cells(3).ForeColor = Drawing.Color.FromArgb(0, 0, 0)
            e.Row.Cells(3).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(13, 73, 125)
            e.Row.Cells(4).ForeColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BorderColor = Drawing.Color.FromArgb(127, 127, 127)
        Else
            e.Row.Cells(0).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(1).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(2).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(3).BackColor = Drawing.Color.FromArgb(255, 255, 255)
            e.Row.Cells(4).BackColor = Drawing.Color.FromArgb(255, 255, 255)
        End If
    End Sub
End Class
